package Thread;
/*
 *
 *@author:    Xavier
 *@data:      2024 - 01 - 10
 *@time:      16:37
 *
 */


// 使用Runnable来创建线程
//创建一个类，实现Runnable，重写run方法


class MyRunnable implements Runnable{
    @Override
    public void run() {
        while (true) {
            System.out.println("hello thread!");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }

    }
}

public class Demo02 {
    public static void main(String[] args) {
        MyRunnable runnable = new MyRunnable();
        Thread t = new Thread(runnable);
        t.start();

        while (true) {
            System.out.println("hello main");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
